package com.wangyuhang.controller;

import com.wangyuhang.vo.Customer;
import com.wangyuhang.vo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
public class controller {
    @RequestMapping("/save")
    @ResponseBody
    public String save() {
        System.out.println("save方法被调用");
        return "{'method':'save'}";
    }

    @RequestMapping("/delete")
    @ResponseBody
    /*普通参数*/
//    public String delete(String name,String age) {
//        System.out.println("delete方法被调用");
//        System.out.println(name+"---"+age);
//        return "{'method':'delete'}";
//    }
    /*pojo参数*/
    /*public String delete(User user) {
        System.out.println("delete方法被调用");
        System.out.println(user);
        return "{'method':'delete'}";
    }*/
    /*pojo引用其他实体类对象*/
   /* public String delete(User user) {
        System.out.println("delete方法被调用");
        System.out.println(user);
        return "{'method':'delete'}";
    }*/
    /*数组对象*/
  /*  public String delete(String [] hobbies) {
        System.out.println("delete方法被调用");
        System.out.println(Arrays.toString(hobbies));
        return "{'method':'delete'}";
    }*/
    /*集合对象*/
    public String delete(@RequestParam List<String> list) {
        System.out.println("delete方法被调用");
        System.out.println(list);
        return "{'method':'delete'}";
    }




    /*Json普通参数、POJO参数、集合参数   要带@RequestBody*/
    /*Json普通参数*/
    @RequestMapping("/json")
    @ResponseBody
    public String listJson(@RequestBody List<String> list) {
        System.out.println("Json数据");
        System.out.println(list);
        return "{'method':'json'}";
    }

    /*Json pojo参数*/
    @RequestMapping("/json2")
    @ResponseBody
    public String listJson2(@RequestBody  User user) {
        System.out.println(user);
        return "Json数据POJO类";
    }

    /*Json pojo*/
    @RequestMapping("/json3")
    @ResponseBody
    public String listJson3(@RequestBody List<User> user) {
        System.out.println(user);
        return "Json数据";
    }

    @RequestMapping("/date")
    @ResponseBody
    public String dateJson(Date date,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") Date date2,
                           @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date3
    ) {
        System.out.println(date);
        System.out.println(date2);
        System.out.println(date3);
        return "date 参数";
    }

}
